package com.heima.cn;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class ServletDemo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取虚拟目录的名称
        String contextPath = req.getContextPath();
        System.out.println(contextPath);//  /request
        //获取servlet的映射路径
        String servletPath = req.getServletPath();
        System.out.println(servletPath);//  /servletDemo01
        //获取访问者的pi地址
        String remoteAddr = req.getRemoteAddr();
        System.out.println(remoteAddr);//  0:0:0:0:0:0:0:1
        //获取请求的消息数据
        String queryString = req.getQueryString();
        System.out.println(queryString);//
        //获取统一的资源标识符
        String requestURI = req.getRequestURI();
        System.out.println(requestURI);// /request/servletDemo01
        //获取统一的资源定位符
        StringBuffer requestURL = req.getRequestURL();
        System.out.println(requestURL);//  http://localhost:8080/request/servletDemo01
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
